package com.woniu.carrent.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.carrent.pojo.TBookcar;
import com.woniu.carrent.pojo.vo.TBookcarVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TBookcarMapper extends BaseMapper<TBookcar> {
    @Select("SELECT \n" +
            "    b.*,\n" +
            "    c.carName AS cname  \n" +
            "FROM t_bookcar b\n" +
            "JOIN t_cardetail cd ON b.cdId = cd.cdId  \n" +
            "JOIN t_car c ON c.carId = cd.carId\n" +
            "${ew.customSqlSegment}")
    List<TBookcar> selectByUserId(@Param("ew") QueryWrapper<TBookcar> queryWrapper);
    @Update("UPDATE t_bookcar SET status = #{status} WHERE bcid = #{bcid}")
    int updateByBcid(@Param("bcid") Integer bcid,
                     @Param("status") Integer status);
    @Delete("DELETE FROM t_bookcar WHERE bcid = #{bcid}")
    int deleteByBcid(@Param("bcid") Integer bcid);
    @Select("select bc.*,seller.userName as sellername,c.`carName` as carname\n" +
            "from t_bookcar bc\n" +
            "join t_cardetail cd on cd.`cdId` = bc.`cdId`\n" +
            "join t_user u on u.`userId` = cd.`userId`\n" +
            "join t_user seller on seller.`userId` = bc.`userId`\n" +
            "join t_car c on c.`carId` = cd.`carId`\n" +
            "where u.userId = #{userid}")
    List<TBookcarVo> selectBookcarBySeller(Integer userid);
}
